<template>
  <div class="seacher_container">
    <div class="seacher_header">
      
        <van-icon class="left" name="arrow-left" @click="goba()"/>
      
      <van-search
        class="seacher"
        v-model="value"
        show-action
        placeholder="请输入搜索关键词"
        @keydown.enter="searchInfo"
      />
    </div>
    <div class="seacher_body">
      <div class="seacher_body_header">
        <p>历史搜索</p>
        <van-icon name="delete" />
      </div>
      <span v-for="(item, index) in his" :key="index">{{ item }}</span>
      &nbsp;&nbsp;&nbsp;&nbsp;
    </div>

    <div class="neirong">
      <!-- 内容 -->
      <div class="zz"></div>
      <div
        class="index_nrirong"
        v-for="(item, index) in list"
        :key="index"
        @click="Coursedetail(item.id)"
      >
        <div class="index_nrirong_one">
          <div class="index_neirong_two">
            <div style="font-size: 0.3rem">
              {{ item.title }}
            </div>
            <div>
              <span
                class="iconfont icon-zhongbiao"
                style="font-size: 0.25rem; color: gray"
                >共8课时</span
              >
            </div>
            <br />
            <div class="why">
              <span style="display: flex">
                <span>
                  <img
                    :src="item.teachers_list[0].teacher_avatar"
                    alt=""
                    style="width: 0.5rem; height: 0.5rem"
                /></span>
                <span
                  style="margin-left: 0.1rem; font-size: 0.25rem; color: gray"
                  >{{ item.teachers_list[0].teacher_name }}</span
                >
              </span>
            </div>
          </div>

          <div class="index_neirong_yi">
            <span style="font-size: 0.24rem; color: gray"
              >{{ item.sales_num }}人已报名</span
            >
            <span style="font-size: 0.3rem; color: #44a426">{{
              item.price
            }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ywtGetbasic } from "../../util/http";

export default {
  data() {
    return {
      value: "",
      list: [],
      his: [],
    };
  },

  methods: {
    goba(){
       this.$router.go(-1);
    },
    searchInfo() {
      //搜索
      let data = {
        keywords: this.value,
      };
      ywtGetbasic(data).then((res) => {
        console.log(res);
        this.list = res.data.data.list;
        console.log(this.list);
      });

      // 如果存储过历史记录
      var histroyKey = localStorage.getItem("keyWords");
      if (histroyKey) {
        var arr = JSON.parse(histroyKey);
        //   去重
        // 设置一个开关
        var bool = true;
        arr.forEach((item) => {
          if (item == this.value) {
            //历史记录中包含value
            bool = false;
          }
        });
        if (bool == true) {
          //当bool为true时，历史记录中不包含value
          arr.push(this.value);
          localStorage.setItem("keyWords", JSON.stringify(arr));
        }
      } else {
        // 没有存储过历史记录
        var keyWordsArr = [];
        keyWordsArr.push(this.value);
        localStorage.setItem("keyWords", JSON.stringify(keyWordsArr));
        //   this.his.push(this.value)
      }
      this.his = JSON.parse(localStorage.getItem("keyWords"));
    },
  },
};
</script>

<style scoped>
.left{
  font-size:0.4rem;
  color:blue !important;
}
body {
  font-size: 0.16rem;
}

.seacher_header {
  display: flex;
  justify-content: space-between;
}

.seacher_body {
  width: 94%;
  height: 0.8rem;
  margin: 0 auto;
}

.seacher_body_header {
  width: 100%;
  height: 0.8rem;
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.3rem;
}

.seacher {
  width: 90%;
}

.left {
  font-size: 0.4rem;
  color: gray;
  margin-left: 0.4rem;
  margin-top: 0.3rem;
}

.van-nav-bar {
  width: 100%;
  height: 0.87rem;
}
div >>> .van-dropdown-menu__bar {
  height: 0.87rem;
  width: 100%;
  position: fixed;
}

body {
  font-size: 0.3rem;
}
.tmk-item span:hover {
  color: red;
}

.zhi {
  color: red !important;
}
.zhi1 {
  color: red !important;
}
.neirong {
  width: 100%;
  height: 100%;
}
.index_toubu {
  border-bottom: 0.01rem solid #eee;
}

.index_nrirong {
  width: 100%;
  background: #f0f2f5;
  box-sizing: border-box;
  padding-top: 0.3rem;
  padding-left: 0.3rem;
  padding-right: 0.3rem;
}
.index_nrirong_one {
  width: 100%;
  height: 3.7rem;
  background: #fff;
  margin: 0 auto;
  box-sizing: border-box;
  padding: 0.5rem 0.24rem;
  border-radius: 0.1rem;
}
.index_fenlei {
  font-size: 0.3rem;
}
.inex_fenlei_one {
  width: 100%;
  height: 3rem;
  margin-top: 1rem;
}

.inex_fenlei_one span {
  width: 1rem;
  height: 0.3rem;
  background: gray;
  margin-left: 0.2rem;
}
.index_neirong_two {
  font-size: 0.3rem;
  border-bottom: 0.01rem solid #eee;
}
p {
  display: flex;
}
img {
  width: 0.4rem;
  height: 0.4rem;
}
.index_neirong_yi {
  height: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.index_daohang {
  width: 100%;
  position: fixed;
}
.hezi {
  width: 100%;
  background: #fff;
}
.hezi1 {
  width: 100%;
  height: 3rem;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.26rem;
  color: gray;
}
.parent-box {
  width: 100%;
  padding-left: 4vw;
  padding-bottom: 2vw;
}
.tm-kind {
  padding-bottom: 2.6vw;
  border-radius: 1px solid #f1f1f1;
}
.tm-kind p {
  font-size: 0.32rem;
  font-size: 3.2vw;
  font-weight: 400;
  color: #595959;
}
.tmk-item span {
  margin: 0 5.13333vw 1.86667vw 0;
  display: inline-block;
  width: 18.4vw;
  height: 8.8vw;
  background: #f5f5f5;
  border-radius: 0.8vw;
  font-size: 3.46667vw;
  font-weight: 400;
  color: #646464;
  text-align: center;
  line-height: 8.8vw;
  overflow: hidden;
}
.seach-btn {
  padding: 4vw 0;
  display: flex;
  justify-content: space-around;
}
.seach-btn button {
  width: 45vw;
  height: 8.8vw;
  border-radius: 1vw;
  font-size: 3.4vw;
}
.seach-btn .sure {
  background-color: #eb6100;
  color: #fff;
}
.choose {
  padding-left: 4vw;
}
.why {
  width: 100%;
  height: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  justify-content: space-between;
}
/* //占位盒子 */
.zz {
  width: 100%;
  height: 1.8rem;
  
}
.ss {
  width: 100%;
  height: 0.2rem;
}
</style>
